package com.example.vo;

import org.apache.zookeeper.*;

public class Java9Test {
    public static void main(String args[])throws Exception{
        // 创建一个与服务器的连接
        ZooKeeper zk = new ZooKeeper("127.0.0.1:2181", 3000, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                // 事件状态为SyncConnected时，说明与服务端的连接已建立好
                System.out.println("事件状态:" + event.getState() +",事件类型:" +  event.getType() +",事件涉及路径:" + event.getPath());
                if (event.getState() == Event.KeeperState.SyncConnected){
                    if (event.getType() == Event.EventType.None && null == event.getPath()){
                        System.out.println("服务器 链接 成功");
                    }
                }else{
                    System.out.println("与服务器断开了链接");
                }
            }
        });
        zk.create("/testRootPath", "我的的测试结果".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
        //zk.delete("/testRootPath",-1);
        System.out.println("yyy");
        zk.close();
    }
}
